package de.tabuma.ssoclient.logik;

import java.util.*;
import de.tabuma.lib.webservice.client.*;
import de.tabuma.ssoclient.entity.*;

/**
 *
 * @author alefen
 */
public class AttributeFacade {

    public static String soapUrl = "https://tabumasso.appspot.com/webservice";

    public static int create(Attribute attribute, String ssoId) throws Exception {
        String methodName = "AttributeService_create";
        String soapAction = "AttributeService_create";

        Class returnType = Integer.class;
        Object params[] = {attribute, ssoId};

        Integer obj = (Integer) ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, returnType, null);
        attribute.setId(obj.longValue());
        AttributeHashFacade.put(attribute,ssoId);
        return obj.intValue();
    }

    public static void update(Attribute attribute, String ssoId) throws Exception {
        String methodName = "AttributeService_update";
        String soapAction = "AttributeService_update";

        Object params[] = {attribute, ssoId};
        ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, null, null);
        AttributeHashFacade.put(attribute,ssoId);
    }

    public static Attribute get(int id, String ssoId) throws Exception {

        String methodName = "AttributeService_get";
        String soapAction = "AttributeService_get";

        Class returnType = Attribute.class;
        Object params[] = {Integer.valueOf(id), ssoId};

        Attribute obj = AttributeHashFacade.get(id, ssoId);
        if(obj==null) {
            obj = (Attribute) ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, returnType, null);
        }
        return obj;
    }

    public static void remove(int id, String ssoId) throws Exception {
        String methodName = "AttributeService_remove";
        String soapAction = "AttributeService_remove";

        Object params[] = {Integer.valueOf(id), ssoId};
        ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, null, null);
        AttributeHashFacade.remove(id,ssoId);
    }

    public static List<Attribute> getList(int userId, String ssoId) throws Exception {
        String methodName = "AttributeService_getList";
        String soapAction = "AttributeService_getList";

        Class returnType = List.class;
        Class returnType1 = Attribute.class;
        Object params[] = {new Integer(userId),ssoId};

        List<Attribute> aList = AttributeHashFacade.getList(userId, ssoId);
        if(aList==null) {
            aList = (List<Attribute>) ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, returnType, returnType1);
            AttributeHashFacade.addList(ssoId, userId, aList);
        }
        return aList;
    }

    public static List<Attribute> getList1(String ssoId) throws Exception {
        String methodName = "AttributeService_getList1";
        String soapAction = "AttributeService_getList1";

        Class returnType = List.class;
        Class returnType1 = Attribute.class;
        Object params[] = {ssoId};

        List<Attribute> aList = AttributeHashFacade.getList(ssoId);
        if(aList==null) {
            aList = (List<Attribute>) ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, returnType, returnType1);
            AttributeHashFacade.addList(ssoId, aList);
        }
        return aList;
    }
}